#include <iostream>
using std::cout;
using std::endl;

class Point
{
public:
    Point()
    : _ix(0)
    , _iy(0)
    {
        cout << "Point()" << endl;
    }

    Point(int x,int y = 1)
    : _ix(x)
    , _iy(y)
    {
        cout << "Point(int,int)" << endl;
    }

    //Point pt(30,50);
    //Point pt2(pt);
    //
    //调用拷贝构造，实参初始化形参的过程如下
    //const Point rhs = pt;
    //又符合拷贝构造的第二种调用时机
    //rhs的创建又会调用拷贝构造
    //
    //const Point rhs = pt;
    //const Point rhs = pt;
    //const Point rhs = pt;
    //const Point rhs = pt;
    //
    /* Point(const Point rhs) */

    //(1)如果没有const，不能确保在函数体中
    //不会通过rhs修改原本的对象的内容
    //(2)如果没有const，不能接受右值属性的对象的复制
    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        /* rhs._ix = 10000; */
        cout << "拷贝构造" << endl;
    }

    void print(){
        cout << "(" << _ix
            << "," << _iy
            << ")" << endl;
    }
private:
    int _ix;
    int _iy;
};

void test0(){
    Point pt(30,50);
    Point pt2 = pt;
    pt2.print();
    pt.print();

    //创建出的临时对象（匿名对象）的生命周期只有当前行
    /* Point(4,8).print(); */
    Point pt3 = Point(4,8);
    pt3.print();

}

int main(void){
    test0();
    return 0;
}
